package com.reworkssm.mybatisdemo.config.security;


import com.reworkssm.mybatisdemo.domain.Account;
import com.reworkssm.mybatisdemo.persistence.AccountMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class UserDetailsServiceImpl implements UserDetailsService {

	private final AccountMapper accountMapper;

	public UserDetailsServiceImpl(AccountMapper accountMapper) {
		this.accountMapper = accountMapper;
	}

	//User Principal finding logic.
	@Override
	public UserDetails loadUserByUsername(String loginId) throws UsernameNotFoundException {
		Account account = accountMapper.getAccountByUsername(loginId);
		UserPrincipal userPrincipal = new UserPrincipal(account);
		return userPrincipal;
	}
}


